package acwing._1_1AlgorithmBasic._4Math;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._4Math
 * @File : Q0867.java
 * @Author : WangRuoyu
 * @Date : 2023/4/3 21:43
 */

import java.io.*;

public class Q0867 {
    static void divide(int x) {
        for (int i = 2; i <= x / i; ++i) {
            if (x % i == 0) {
                int s = 0;
                while (x % i == 0) {
                    s++;
                    x /= i;
                }
                System.out.println(i + " " + s);
            }
        }
        if (x > 1) System.out.println(x + " " + 1);
        System.out.println();
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            divide(Integer.parseInt(words[0]));
        }
        wr.flush();
    }
}
